//Inventory Script
var inv_image = LoadImage("inv.png");
var exit = false;
var items = [];
var selected_item = 0;
var basexy = [90,185];
var f = GetSystemFont();
function Inv()
{
items = [];
if(!this instanceof Inv) return new Inv();
}
Inv.prototype.addItem = function(name,image)
{
	var item = {
		name: name,
		image:image
		};
	
	items.push(item);
}
function renderInv()
{
	inv_image.blit(60,45);
	for(i=0;i<items.length;i++)
	{
		var itemimage = LoadImage(items[i].image);
		itemimage.blit(basexy[0]+(35*i),basexy[1]);
	}
}
Inv.prototype.openInventory = function()
{
	while(!exit)
	{
		renderInv();
		OutlinedRectangle(basexy[0]+(35*selected_item),basexy[1],16,16,CreateColor(255,255,0));
		f.drawText(90,400,items[selected_item].name);
		FlipScreen();
		while(AreKeysLeft())
	  {

			switch(GetKey()) 
			{
					case KEY_I:
						exit = true;
					break;
					case KEY_LEFT:
						if(selected_item > 0)
						{
							selected_item -= 1;
						}
					break;
					case KEY_RIGHT:
						if(items.length-1 > selected_item)
						{
							selected_item += 1;
						}
					break;
			}
    }
	}
	exit = false;
}